package org.itheima.googleplay.ui.holder;

import java.util.List;

import org.itheima.googleplay.R;
import org.itheima.googleplay.ui.weiget.RatioLayout;
import org.itheima.googleplay.utils.BitmapHelper;
import org.itheima.googleplay.utils.Constants;
import org.itheima.googleplay.utils.UIUtils;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

/**
 * @包名: org.itheima.googleplay.ui.holder
 * @类名: AppDetailPicHolder
 * @作者: 肖琦
 * @创建时间 : 2015-3-24 上午10:58:12
 * 
 * @描述: 应用详情页面-图片部分
 * 
 * @SVN版本: $Rev: 20 $
 * @更新人: $Author: xq $
 * @更新时间: $Date: 2015-03-24 16:01:24 +0800 (星期二, 24 三月 2015) $
 * 
 * @更新描述:
 */
public class AppDetailPicHolder extends BaseHolder<List<String>>
{
	@ViewInject(R.id.app_detail_pic_iv_container)
	private LinearLayout	mPicContainer;

	@Override
	protected View initView()
	{
		View view = View.inflate(UIUtils.getContext(), R.layout.app_detail_pic, null);

		// 注入
		ViewUtils.inject(this, view);

		return view;
	}

	@Override
	protected void refreshUI(List<String> data)
	{

		if (data == null) { return; }

		// 清空容器
		mPicContainer.removeAllViews();

		// 动态的添加图片
		for (int i = 0; i < data.size(); i++)
		{
			String url = Constants.BASE_IMAGE_URL + data.get(i);

			ImageView iv = new ImageView(UIUtils.getContext());
			iv.setImageResource(R.drawable.ic_default);// 设置默认图片
			BitmapHelper.display(iv, url);// 图片加载

			RatioLayout layout = new RatioLayout(UIUtils.getContext());
			layout.setRatio(0.6f);
			layout.setRelative(RatioLayout.RELATIVE_WIDTH);
			layout.addView(iv);

			LayoutParams params = new LayoutParams(UIUtils.dip2px(100), 0);
			if (i != 0)
			{
				params.leftMargin = UIUtils.dip2px(10);
			}
			// 添加到容器中
			mPicContainer.addView(layout, params);
		}
	}

}
